package com.smart.sso.server.controller.admin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smart.mvc.model.Pagination;
import com.smart.mvc.model.Result;
import com.smart.mvc.validator.Validator;
import com.smart.mvc.validator.annotation.ValidateParam;
import com.smart.sso.server.common.LoginUser;
import com.smart.sso.server.controller.common.BaseController;
import com.smart.sso.server.model.Log;
import com.smart.sso.server.service.LogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "日志管理")
@Controller
@RequestMapping("/admin/log")
public class LogController extends BaseController {
	@Resource
	LogService logService;
	
	@ApiOperation("初始页")
	@RequestMapping(method = RequestMethod.GET)
	public String execute(Model model) {
		return "/admin/log";
	}
	
	@ApiOperation("列表")
	@RequestMapping(value = "/list" , method = RequestMethod.GET)
	public @ResponseBody Result list(
			@ApiParam(value = "名称") String account,
			@ApiParam(value = "起始时间") String startDate,
			@ApiParam(value = "结束时间") String endDate ,
			@ApiParam(value = "开始页数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageNo,
			@ApiParam(value = "显示条数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageSize,
			HttpServletRequest request) {
		LoginUser loginUser = (LoginUser)request.getSession().getAttribute("CURRENT_USER");
		return Result.createSuccessResult().setData(logService.findPaginationByAccountAndDate(loginUser.getUserId(), account, startDate, endDate , new Pagination<Log>(pageNo , pageSize)));
	}
	
//	@ApiOperation("列表")
//	@RequestMapping(value = "/list" , method = RequestMethod.GET)
//	public @ResponseBody Result list(
//			@ApiParam(value = "开始页码" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageNo,
//			@ApiParam(value = "显示条数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageSize) {
//		return Result.createSuccessResult().setData(logService.findAllPagination(new Pagination<Log>(pageNo , pageSize) ));
//	}
//	
//	@ApiOperation("根据用户名查找")
//	@RequestMapping(value = "/findbyaccount" , method = RequestMethod.GET)
//	public @ResponseBody Result findByAccount(
//			@ApiParam(value = "名称") String account,
//			@ApiParam(value = "开始页数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageNo,
//			@ApiParam(value = "显示条数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageSize){
//		return Result.createSuccessResult().setData(logService.findPaginationByAccount(account, new Pagination<Log>(pageNo , pageSize)));
//	}
//	
//	@ApiOperation("根据时间查找")
//	@RequestMapping(value = "/findbydate" , method = RequestMethod.GET)
//	public @ResponseBody Result findByDate(
//			@ApiParam(value = "起始时间") String startDate,
//			@ApiParam(value = "结束时间") String endDate,
//			@ApiParam(value = "开始页数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageNo,
//			@ApiParam(value = "显示条数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageSize) {
//		return Result.createSuccessResult().setData(logService.findPaginationByDate(startDate, endDate , new Pagination<Log>(pageNo , pageSize)));
//	}
//	
//	@ApiOperation("根据用户和时间查找")
//	@RequestMapping(value = "/findbyaccountanddate" , method = RequestMethod.GET)
//	public @ResponseBody Result findByAccountAndDate(
//			@ApiParam(value = "名称") String account,
//			@ApiParam(value = "起始时间") String startDate,
//			@ApiParam(value = "结束时间") String endDate ,
//			@ApiParam(value = "开始页数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageNo,
//			@ApiParam(value = "显示条数" , required = true) @ValidateParam({Validator.NOT_BLANK}) Integer pageSize) {
//		return Result.createSuccessResult().setData(logService.findPaginationByAccountAndDate(account, startDate, endDate , new Pagination<Log>(pageNo , pageSize)));
//	}
}
